﻿#include <iostream>
#include <cmath>
/******************************************************
*
* @file     main.cpp
* @brief    计算相对原点的偏移点相对于原点的偏移距离和角度
*
* @author   kiyose
* @date     2024/04/26
* @history
**********************************************************/

/**
 * @brief The polar class
 * 表示偏移的距离和角度
 */
struct polar{
    double distance;
    double angle;
};
/**
 * @brief The rect class
 * 表示需要测算的偏移点相对于原点的坐标位置
 */
struct rect{
    double x;
    double y;
};
polar rect_to_polar (rect xypos);
void show_polar(polar dapos);

int main()
{
    using namespace std;
    rect rplace;
    polar pplace;

    cout << "Enter the x and y values: ";
    while(cin>>rplace.x >>rplace.y)
    {
        pplace = rect_to_polar(rplace);
        show_polar(pplace);
        cout << "Next two numbers (q to quit)";
    }
    cout << "Done.\n";
    return 0;
}
/**
 * @brief rect_to_polar
 * @param xypos     偏移点的相对坐标
 * @return
 */
polar rect_to_polar(rect xypos)
{
    using namespace std;
    polar answer;

    answer.distance = sqrt(xypos.x *xypos.x+xypos.y *xypos.y);
    answer.angle = atan2(xypos.y,xypos.x);
    return answer;
}
/**
 * @brief show_polar
 * @param dapos     偏移距离与角度
 */
void show_polar(polar dapos)
{
    using namespace std;
    const double Rad_to_deg = 57.29577951;

    cout << "distance = "<< dapos.distance;
    cout << ",angle = "<<dapos.angle*Rad_to_deg;
    cout << " degrees\n";
}
